import { banner , news ,goods} from "../../utils/interface";
Page({
  data: {
    swiperList: [],
    concentrationList: [],
    tuijianList: [],
    desc:true,
    page:1,
    imgNav:[
      {img:'../../images/1.png',title:'签到'},
      {img:'../../images/2.png',title:'礼券'},
      {img:'../../images/3.png',title:'砍价'},
      {img:'../../images/4.png',title:'专栏'}
    ]
  },
  onLoad() {
    this.getBannerList();
    this.getNewsList()
    this.getGoodsList()
  },
  //获取轮播图
  async getBannerList() {
    let { data: res } = await banner();
    this.setData({
      swiperList: res.data,
    });
  },
  // 获取文章列表
  async getNewsList(){
    let {data:res} = await news()
    // console.log(res);
    this.setData({
      concentrationList:res.data
    })
  },
  // 获取商品列表
  async getGoodsList(){ 
    let page = this.data.page
    let {data:res} = await goods({page,pageSize:8})
    // let arr = res.data.filter(item => {
    //   return item.recommendStatusStr.includes('推荐')
    // })
    if(res.data.length < 8){
      this.data.desc = false
    } 
    // console.log(res);
    this.setData({
      tuijianList:this.data.tuijianList.concat(res.data),
      desc:this.data.desc
    })
  },
  // 图片预览
  proviewImg(e){
    // console.log(e);
    let {imgUrl} = e.currentTarget.dataset
    let arr = this.data.swiperList.map(item =>{
      return item.picUrl
    })
    wx.previewImage({
      current:imgUrl,
      showmenu:true,
      urls:arr
    
    })
  },
  // 进入详情页
  godetail(e) {
    // console.log(e);
    let id = e.detail;
    wx.navigateTo({
      url: "/pages/detail/detail?id=" + id,
    });
  },
  onReachBottom(){
    if(this.data.desc) {
      this.data.page+=1
      this.getGoodsList()
    }
  }
});
